<template>
  <div style="">
    <!-- <span style="color: #409EFF;margin-left: 10px">设置必填项</span> -->
    <el-row>
      <el-col style="padding: 20px;">
        <el-table
          ref="multipleTable"
          :data="tableData"
          height="700"
          style="width: 100%; margin-top: -30px"
          class="table"
          border
        >

          <el-table-column
            prop="codeName"
            label="名称"
            min-width="150"
            header-align="center"
            align="center"
          />
          <el-table-column
            label="设置必填项"
            min-width="300"
            header-align="center"
            align="center"
          >
            <template slot-scope="scope">
              <el-radio-group v-model="scope.row.value" @change="changeradio(scope.$index, scope.row)">
                <el-radio label="1">必填项（有星号）</el-radio>
                <el-radio label="2">非必填项（无星号）</el-radio>
                <el-radio label="3">非必填项（有星号）</el-radio>
              </el-radio-group>
            </template>
          </el-table-column>
        </el-table>
        <el-pagination
          style="float: right"
          :current-page="currentPage"
          :page-sizes="[5, 10, 15, 20]"
          :page-size="pagesize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="pageTotal"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </el-col>
    </el-row>
  </div>
</template>

<script>
  import { selectRequired, saveRequired} from  '@/api/back-management/triage-manage/set_requireditem.js'
  export default {
    name: 'SetRequiredItem',
    components: {  },
    data() {
      return{
        tableData: [],
        /* 表格分页参数*/
        currentPage: 1,
        pagesize: 10,
        pageTotal: 0,
        /* 用户信息 */
        userId: this.$store.getters.userId,
        hospitalId: this.$store.getters.hospitalId,
        apiToken: this.$store.getters.apiToken
      }
    },
    created() {
      this.selectRequired()
    },
    methods: {
      /* 操作 */
      changeradio(index, row) {
        const obj = {}
        obj.hospitalid = this.hospitalId
        obj.code = row.code
        obj.codeName = row.codeName
        obj.value = row.value
        obj.starttime = row.starttime
        obj.endtime = row.endtime
        obj.createdAt = row.createdAt
        obj.updataAt = row.updataAt
        obj.id = row.id
        obj.status = row.status
        obj.type = row.type
        saveRequired(obj).then(res => {
          if (res.code === 9999) {
            this.$message({
              type: 'error',
              message: '修改失败'
            })
          } else {
            this.$message({
              type: 'success',
              message: '修改成功！'
            })
            this.selectRequired()
          }
        }).catch(err => {
          this.$message.error(err)
        })
      },
      selectRequired(){
        let data = {
          hospitalId: this.hospitalId
        }
        selectRequired(data).then(res => {
          if(res.code === 0){
            this.tableData = res.data.list
            this.pageTotal = res.data.total
          }
        }).catch(err => {
          this.$message.error(err)
        })
      },

      // 分页尺寸改变
      handleSizeChange(size) {
        this.pagesize = size
      },
      // 分页换页
      handleCurrentChange(currentPage) {
        this.currentPage = currentPage
      }
    }
  }
</script>

<style>
</style>
